package com.gopay.common.domain.bank.wechat.micro.res;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

import com.gopay.common.domain.bank.wechat.micro.MicroPayResBaseMsg;
import com.thoughtworks.xstream.annotations.XStreamAlias;

/** 
 * 小额免密支付--退款查询响应类
 * @ClassName: MicroRefundQueryResMsg 
 * @author w_jiqing 
 * @date 2017年5月24日 上午9:43:13  
 */ 
@XStreamAlias("xml")
public class MicroRefundQueryResMsg extends MicroPayResBaseMsg{

 
    private static final long serialVersionUID = 3745338018115576745L;
    /**
     * 业务结果
     */
    private String result_code= "";
    /**
     * 商户号
     */
    private String mch_id= "";
    /**
     * 设备号
     */
    private String device_info= "";
    /**
     * 随机字符串
     */
    private String nonce_str= "";
    /**
     * 错误代码
     */
    private String err_code= "";
    
    /**
     * 错误代码描述
     */
    private String err_msg= "";
    /**
     * 签名
     */
    private String sign= "";
    /**
     * 威富通订单号
     */
    private String transaction_id= "";
    
    /**
     * 新增字段
     */
    private String out_transaction_id ="";
    /**
     * 商户订单号
     */
    private String out_trade_no= "";
    /**
     * 退款笔数
     */
    private int refund_count ;
    
    /**
     * 新增字段
     */
    private String trade_type ="";
    /**
     *  新增字段
     */
    private String total_fee = "";
    private String cash_fee;
      
    /**
     * 退款订单明细
     */
    private List<MicroRefundQueryResItem> refundItems;
    private String trade_state_desc;
    
    /**
     * 因响应报文退款内容的元素名称不确定，因此需要将<out_refund_no_$n>元素之前的
     * xml报文截取出来，并转换成MicroRefundQueryResMsg类对象,之后将剩余的xml
     * 报文通过该方法映射为该类的集合元素
     * @param itemString 退款查询响应xml报文</refund_count>元素之后的
     * 所有xml元素的字符串
     */
    public void fillItem(String itemString) {
        refundItems = new ArrayList<MicroRefundQueryResItem>(refund_count);
        for (int i = 0; i < refund_count; i++) {
            MicroRefundQueryResItem item = new MicroRefundQueryResItem();
            if (itemString.contains("<out_refund_no_" + i + ">")) {
                item.setOut_refund_no(StringUtils.substringBetween(itemString, "<out_refund_no_" + i + "><![CDATA[", "]]></"));
            }
            
            if (itemString.contains("<out_refund_id_" + i + ">")) {
                item.setOut_refund_id(StringUtils.substringBetween(itemString, "<out_refund_id_" + i + "><![CDATA[", "]]></"));
            }
            
            if (itemString.contains("<refund_id_" + i + ">")) {
                item.setRefund_id(StringUtils.substringBetween(itemString, "<refund_id_" + i + "><![CDATA[", "]]></"));
            }
            if (itemString.contains("<refund_channel_" + i + ">")) {
                item.setRefund_channel(StringUtils.substringBetween(itemString, "<refund_channel_" + i + "><![CDATA[", "]]></"));
            }
            if (itemString.contains("<refund_fee_" + i + ">")) {
                item.setRefund_fee(StringUtils.substringBetween(itemString, "<refund_fee_" + i + "><![CDATA[", "]]></"));
            }
            if (itemString.contains("<coupon_refund_fee_" + i + ">")) {
                item.setCoupon_refund_fee(StringUtils.substringBetween(itemString, "<coupon_refund_fee_" + i + "><![CDATA[", "]]></"));
            }
            if (itemString.contains("<refund_time_" + i + ">")) {
                item.setRefund_time(StringUtils.substringBetween(itemString, "<refund_time_" + i + "><![CDATA[", "]]></"));
            }
            if (itemString.contains("<refund_status_" + i + ">")) {
                item.setRefund_status(StringUtils.substringBetween(itemString, "<refund_status_" + i + "><![CDATA[", "]]></"));
            }
            refundItems.add(item);
        }
    }

    
    public String getResult_code() {
        return result_code;
    }
    public void setResult_code(String result_code) {
        this.result_code = result_code;
    }
    public String getMch_id() {
        return mch_id;
    }
    public void setMch_id(String mch_id) {
        this.mch_id = mch_id;
    }
    public String getDevice_info() {
        return device_info;
    }
    public void setDevice_info(String device_info) {
        this.device_info = device_info;
    }
    public String getNonce_str() {
        return nonce_str;
    }
    public void setNonce_str(String nonce_str) {
        this.nonce_str = nonce_str;
    }
    public String getErr_code() {
        return err_code;
    }
    public void setErr_code(String err_code) {
        this.err_code = err_code;
    }
    public String getSign() {
        return sign;
    }
    public void setSign(String sign) {
        this.sign = sign;
    }
    public String getTransaction_id() {
        return transaction_id;
    }
    public void setTransaction_id(String transaction_id) {
        this.transaction_id = transaction_id;
    }
    
    public String getTrade_type() {
        return trade_type;
    }


    public void setTrade_type(String trade_type) {
        this.trade_type = trade_type;
    }


    public String getOut_trade_no() {
        return out_trade_no;
    }
    public void setOut_trade_no(String out_trade_no) {
        this.out_trade_no = out_trade_no;
    }
  
    
    public int getRefund_count() {
        return refund_count;
    }


    public String getErr_msg() {
        return err_msg;
    }


    public void setErr_msg(String err_msg) {
        this.err_msg = err_msg;
    }


    public String getOut_transaction_id() {
        return out_transaction_id;
    }


    public void setOut_transaction_id(String out_transaction_id) {
        this.out_transaction_id = out_transaction_id;
    }


    public void setRefund_count(int refund_count) {
        this.refund_count = refund_count;
    }


    public List<MicroRefundQueryResItem> getRefundItems() {
        return refundItems;
    }
    public void setRefundItems(List<MicroRefundQueryResItem> refundItems) {
        this.refundItems = refundItems;
    }


    public String getTotal_fee() {
        return total_fee;
    }


    public void setTotal_fee(String total_fee) {
        this.total_fee = total_fee;
    }


	public String getTrade_state_desc() {
		return trade_state_desc;
	}


	public void setTrade_state_desc(String trade_state_desc) {
		this.trade_state_desc = trade_state_desc;
	}

    public String getCash_fee() {
        return cash_fee;
    }

    public void setCash_fee(String cash_fee) {
        this.cash_fee = cash_fee;
    }
}
